package fun.easycode.webterminal.adapter.api;

import fun.easycode.webterminal.common.contract.PageDTO;
import fun.easycode.webterminal.common.contract.R;
import fun.easycode.webterminal.service.MachineService;
import fun.easycode.webterminal.service.cmd.MachineBatchDeleteCmd;
import fun.easycode.webterminal.service.cmd.MachinePageQry;
import fun.easycode.webterminal.service.cmd.MachineSaveCmd;
import fun.easycode.webterminal.service.dto.MachineDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "机器")
@RestController
@RequestMapping("/api/machine")
public class MachineApi {

    private final MachineService machineService;

    @Autowired
    public MachineApi(MachineService machineService) {
        this.machineService = machineService;
    }

    @Operation(summary = "分页查询机器")
    @GetMapping("/page")
    public R<PageDTO<MachineDTO>> page(MachinePageQry cmd) {
        return machineService.page(cmd);
    }

    @Operation(summary = "保存机器(新建/编辑)")
    @PostMapping("/save")
    public R<String> save(@RequestBody MachineSaveCmd cmd) {
        return machineService.save(cmd);
    }

    @Operation(summary = "删除机器")
    @PostMapping("/delete")
    public R<String> delete(@RequestParam String id) {
        return machineService.delete(id);
    }

    @Operation(summary = "批量删除机器")
    @PostMapping("/batch-delete")
    public R<String> batchDelete(@RequestBody MachineBatchDeleteCmd cmd) {
        return machineService.batchDelete(cmd);
    }

    @Operation(summary = "根据id查询机器")
    @GetMapping("/get-by-id")
    public R<MachineDTO> getById(@RequestParam String id) {
        return machineService.getById(id);
    }
}
   